import { Camera3D, Scene3D, WebGLRenderer3D } from 'feng3d-three';
import { ParallaxBarrierEffect } from '../thirdparty/three/imports';

export class ParallaxBarrierEffect3D
{
    _parallaxBarrierEffect: ParallaxBarrierEffect;

    constructor(renderer: WebGLRenderer3D)
    {
        this._parallaxBarrierEffect = new ParallaxBarrierEffect(renderer._webGLRenderer);
    }

    setSize(width: number, height: number)
    {
        this._parallaxBarrierEffect.setSize(width, height);
    }

    render(scene: Scene3D, camera: Camera3D)
    {
        // 修复渲染前更新摄像机矩阵数据
        // @see https://github.com/mrdoob/three.js/blob/r149/src/renderers/WebGLRenderer.js#L963
        camera.updateMatrixWorld();
        //
        this._parallaxBarrierEffect.render(scene._scene, camera._camera);
    }
}
